import _regeneratorRuntime from "@babel/runtime/regenerator";
import _asyncToGenerator from "@babel/runtime/helpers/esm/asyncToGenerator";

/**
 * service: 二级域名单点登录配置
 * @date: 2019-6-27
 */
import request from 'utils/request';
import { CPAAS_IAM, CPAAS_PLATFORM } from 'utils/config';
import { getCurrentOrganizationId, isTenantRoleLevel } from 'utils/utils';
var organizationId = getCurrentOrganizationId();
/**
 * 查询列表
 * @async
 * @function queryConfig
 * @param {Object} params - 查询参数
 */

export function queryConfig(_x) {
  return _queryConfig.apply(this, arguments);
}
/**
 * 创建配置
 * @async
 * @function createConfig
 * @param {Object} params - 查询参数
 */

function _queryConfig() {
  _queryConfig = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(params) {
    return _regeneratorRuntime.wrap(function _callee$(_context) {
      while (1) {
        switch (_context.prev = _context.next) {
          case 0:
            return _context.abrupt("return", request("".concat(CPAAS_IAM, "/v1/").concat(isTenantRoleLevel() ? "".concat(organizationId, "/") : '', "domains"), {
              method: 'GET',
              query: params
            }));

          case 1:
          case "end":
            return _context.stop();
        }
      }
    }, _callee);
  }));
  return _queryConfig.apply(this, arguments);
}

export function createConfig(_x2) {
  return _createConfig.apply(this, arguments);
}
/**
 * 删除配置
 * @async
 * @function deleteConfig
 * @param {Object} params - 查询参数
 */

function _createConfig() {
  _createConfig = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2(params) {
    return _regeneratorRuntime.wrap(function _callee2$(_context2) {
      while (1) {
        switch (_context2.prev = _context2.next) {
          case 0:
            return _context2.abrupt("return", request("".concat(CPAAS_IAM, "/v1/").concat(isTenantRoleLevel() ? "".concat(organizationId, "/") : '', "domains"), {
              method: 'POST',
              body: params
            }));

          case 1:
          case "end":
            return _context2.stop();
        }
      }
    }, _callee2);
  }));
  return _createConfig.apply(this, arguments);
}

export function deleteConfig(_x3) {
  return _deleteConfig.apply(this, arguments);
}
/**
 * 修改配置
 * @async
 * @function editConfig
 * @param {Object} params - 查询参数
 */

function _deleteConfig() {
  _deleteConfig = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee3(params) {
    return _regeneratorRuntime.wrap(function _callee3$(_context3) {
      while (1) {
        switch (_context3.prev = _context3.next) {
          case 0:
            return _context3.abrupt("return", request("".concat(CPAAS_IAM, "/v1/").concat(isTenantRoleLevel() ? "".concat(organizationId, "/") : '', "domains"), {
              method: 'DELETE',
              body: params
            }));

          case 1:
          case "end":
            return _context3.stop();
        }
      }
    }, _callee3);
  }));
  return _deleteConfig.apply(this, arguments);
}

export function editConfig(_x4) {
  return _editConfig.apply(this, arguments);
}
/**
 * 获取配置明细
 * @async
 * @function getConfigDetail
 * @param {Object} params - 查询参数
 */

function _editConfig() {
  _editConfig = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee4(params) {
    return _regeneratorRuntime.wrap(function _callee4$(_context4) {
      while (1) {
        switch (_context4.prev = _context4.next) {
          case 0:
            return _context4.abrupt("return", request("".concat(CPAAS_IAM, "/v1/").concat(isTenantRoleLevel() ? "".concat(organizationId, "/") : '', "domains"), {
              method: 'PUT',
              body: params
            }));

          case 1:
          case "end":
            return _context4.stop();
        }
      }
    }, _callee4);
  }));
  return _editConfig.apply(this, arguments);
}

export function getConfigDetail(_x5) {
  return _getConfigDetail.apply(this, arguments);
}
/**
 * 获取模板配置提示信息详情
 */

function _getConfigDetail() {
  _getConfigDetail = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee5(params) {
    var domainId;
    return _regeneratorRuntime.wrap(function _callee5$(_context5) {
      while (1) {
        switch (_context5.prev = _context5.next) {
          case 0:
            domainId = params.domainId;
            return _context5.abrupt("return", request("".concat(CPAAS_IAM, "/v1/").concat(isTenantRoleLevel() ? "".concat(organizationId, "/") : '', "domains/").concat(domainId), {
              method: 'GET'
            }));

          case 2:
          case "end":
            return _context5.stop();
        }
      }
    }, _callee5);
  }));
  return _getConfigDetail.apply(this, arguments);
}

export function fetchMessageDetail(_x6) {
  return _fetchMessageDetail.apply(this, arguments);
}

function _fetchMessageDetail() {
  _fetchMessageDetail = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee6(params) {
    return _regeneratorRuntime.wrap(function _callee6$(_context6) {
      while (1) {
        switch (_context6.prev = _context6.next) {
          case 0:
            return _context6.abrupt("return", request(isTenantRoleLevel() ? "".concat(CPAAS_PLATFORM, "/v1/").concat(organizationId, "/static-texts/text-code") : "".concat(CPAAS_PLATFORM, "/v1/static-texts/text-code"), {
              method: 'GET',
              query: params
            }));

          case 1:
          case "end":
            return _context6.stop();
        }
      }
    }, _callee6);
  }));
  return _fetchMessageDetail.apply(this, arguments);
}